import React, { useState, createContext, useContext } from "react";

const CountContext = createContext(0)
function ShowCount(){
  const count = useContext(CountContext)
  return <div>{count}</div>
}

function App() {
  const [count, setCount] = useState(0);

  return (
    <>
      <div>次数:{count}</div>
      <button onClick={() => {setCount(count + 1);}}>增加次数</button>
      <CountContext.Provider value={count}>
        <ShowCount/>
      </CountContext.Provider>
    </>
  );
}
export default App;
